package cst.a000tyy.recyclerviewtest;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.widget.Toast;

import java.util.ArrayList;
import java.util.List;

import Adapter.MyAdapter;
import Bean.ArticleBean;
import Model.ArticleModel;
import iface.ArticleListener;

public class MainActivity extends AppCompatActivity implements ArticleListener{
    private List<ArticleBean> list;
    private RecyclerView recyclerView;
    private RecyclerView.LayoutManager layoutManager;
    private MyAdapter mAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initRecyclerView();
        ArticleModel AM=new ArticleModel();
        AM.getrusultlist("article",2,"2ts2j910hv4m270hipde4a67d7",this);
    }

    private void initRecyclerView() {
        recyclerView=(RecyclerView)findViewById(R.id.recyclerview);
        layoutManager=new LinearLayoutManager(this);
        recyclerView.setLayoutManager(layoutManager);
        //list=getData();
        mAdapter=new MyAdapter(this);
        mAdapter.setList(list);
        recyclerView.setAdapter(mAdapter);
    }

   /* private List<ArticleBean> getData() {
        List<ArticleBean> list=new ArrayList<ArticleBean>();
        ArticleBean art;
        for(int i;i<=;)
        list


        return list;
    }*/

    @Override
    public void onResponse(List<ArticleBean> list) {
        this.list=list;
        mAdapter.setList(list);
    }

    @Override
    public void onFail(String msg) {
        Toast.makeText(this, "fail"+msg, Toast.LENGTH_SHORT).show();
    }
}
